import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
//import locale from "element-ui/lib/locale/lang/en"; // lang i18n

import "@/styles/index.scss"; // global css

import App from "./App";
import store from "./store";
import router from "./router";
import { option } from "runjs";

import "@/icons"; // icon
import "@/permission"; // permission control

// Vue.directive("自定义指令名"，指令对象)

// Vue.directive("imageError2", {
//   // bind(binging, value) {
//   //   console.log(binging, value, 888);
//   // },
//   inserted(dom, { value }) {
//     //console.log(this, 55555);
//     //console.log(dom, value, 999);
//     //dom.style.color = value[1];
//     //dom.src='@/assets/common/img.jpeg'

//     dom.onerror = () => {
//       dom.src =
//         "http://artful-1304861100.cos.ap-guangzhou.myqcloud.com/6012192.jpg";
//     };
//   }
// });
// Vue.filter('aa',function(){})

import * as derec from "@/directives";
//console.log(derec, 3333); //  {imageError2:obj,err:obj2}
//  获取所有的键名  imageError2  err
// var arr = Object.keys(derec);  //=>  ["imageError2", "err"]  获取对象中键
// console.log(arr,4444);
// arr.forEach(key=>{
//   Vue.directive(key,derec[key])  //  =>  derec[arr[0]]
// })

// Vue.directive("imageError2", {})
// Vue.directive("err", {})

// import pageTools from "@/components/common/pageTools";
// Vue.component("pageTools", pageTools);

import components from "@/components";
Vue.use(components);

Vue.prototype.Bus = new Vue();

// Vue.use({
//   install(Vue){
//     Vue.component("pageTools", pageTools);
//   }
// })

Object.keys(derec).forEach(key => {
  Vue.directive(key, derec[key]);
});

/* 时间过滤器 */
import dayjs from "dayjs";

/* 
封装：
第一个参数表示的是  需要被过滤的数据   

第二个参数  表示按照什么格式来进行处理过滤
timeobj(obj,parmas)

调用：
timeobj(传入参数【在封装中是用第二个参数来接收的】)

 */

import Print from "vue-print-nb";

Vue.use(Print);

import checkPermission from "@/mixin/checkPermission";
Vue.mixin(checkPermission);

Vue.filter("timeObj", function(obj, params) {
  return dayjs(obj).format(params);
});

import * as formatDate from "@/filters"; //  {numberFormatter:function(){},}
Object.keys(formatDate).forEach(key => {
  Vue.filter(key, formatDate[key]);
});

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
//  2021-01-26
// if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }
import i18n from "@/lang";
//console.log(i18n,99);
// set ElementUI lang to EN
//Vue.use(ElementUI, { locale });
// 如果想要中文版 element-ui，按如下方式声明
// 设置element为当前的语言
Vue.use(ElementUI, {

  i18n: (key, value) => i18n.t(key, value)
});

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  i18n,
  render: h => h(App)
});
